﻿using System;
using DiskInspector.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DiskInspector.Test
{
    [TestClass]
    public class DataParserTest
    {
        private byte[] array;

        [TestInitialize]
        public void Initialize()
        {
            array = new byte[9];
            array[0] = 0x56;
            array[1] = 0x34;
            array[2] = 0x12;
            array[3] = 0x00;
            array[4] = 0xFF;
            array[5] = 0xE7;
            array[6] = 0x03;
            array[7] = 0x3F;
            array[8] = 0x01;
        }

        [TestMethod]
        public void TestDataParserWithFieldLength()
        {
            var model = DataParser.Parse<TestFieldLengthModel>(array);

            Assert.AreEqual(1193046, model.IntValue);
            Assert.AreEqual(255, model.ByteValue);
            Assert.AreEqual(999, model.ShortValue);

            Assert.AreEqual(63, model.ByteValue1);
            Assert.AreEqual(4, model.ShortValue1);
        }

        [TestMethod]
        public void TestDataParserWithBlockLength()
        {
            var fullArray = new byte[18];
            array.CopyTo(fullArray, 0);
            array.CopyTo(fullArray, 9);

            var model = DataParser.Parse<TestBlockLengthModel>(fullArray);

            Assert.AreEqual(1193046, model.BlockValues[0].IntValue);
            Assert.AreEqual(255, model.BlockValues[0].ByteValue);
            Assert.AreEqual(999, model.BlockValues[0].ShortValue);

            Assert.AreEqual(63, model.BlockValues[0].ByteValue1);
            Assert.AreEqual(4, model.BlockValues[0].ShortValue1);

            Assert.AreEqual(1193046, model.BlockValues[1].IntValue);
            Assert.AreEqual(255, model.BlockValues[1].ByteValue);
            Assert.AreEqual(999, model.BlockValues[1].ShortValue);

            Assert.AreEqual(63, model.BlockValues[1].ByteValue1);
            Assert.AreEqual(4, model.BlockValues[1].ShortValue1);
        }
    }
}
